package o;

import android.net.Uri;
import android.util.Base64;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.ParserException;
import com.google.android.exoplayer2.upstream.DataSpec;
import com.huawei.hms.common.data.DataBufferSafeParcelable;
import java.io.IOException;
import java.net.URLDecoder;

public final class alg extends alf {
    @Nullable
    private byte[] ˎ;
    @Nullable
    private DataSpec ˏ;
    private int ॱ;

    public alg() {
        super(false);
    }

    public long ˋ(DataSpec dataSpec) throws IOException {
        ˊ(dataSpec);
        this.ˏ = dataSpec;
        Uri uri = dataSpec.ˎ;
        String scheme = uri.getScheme();
        if (DataBufferSafeParcelable.DATA_FIELD.equals(scheme)) {
            String[] ˎ = anr.ˎ(uri.getSchemeSpecificPart(), ",");
            if (ˎ.length != 2) {
                throw new ParserException("Unexpected URI format: " + uri);
            }
            String str = ˎ[1];
            if (ˎ[0].contains(";base64")) {
                try {
                    this.ˎ = Base64.decode(str, 0);
                } catch (Throwable e) {
                    throw new ParserException("Error while parsing Base64 encoded string: " + str, e);
                }
            }
            this.ˎ = anr.ˊ(URLDecoder.decode(str, "US-ASCII"));
            ˎ(dataSpec);
            return (long) this.ˎ.length;
        }
        throw new ParserException("Unsupported scheme: " + scheme);
    }

    public int ˋ(byte[] bArr, int i, int i2) {
        if (i2 == 0) {
            return 0;
        }
        int length = this.ˎ.length - this.ॱ;
        if (length == 0) {
            return -1;
        }
        length = Math.min(i2, length);
        System.arraycopy(this.ˎ, this.ॱ, bArr, i, length);
        this.ॱ += length;
        ˊ(length);
        return length;
    }

    @Nullable
    public Uri ˊ() {
        return this.ˏ != null ? this.ˏ.ˎ : null;
    }

    public void ॱ() throws IOException {
        if (this.ˎ != null) {
            this.ˎ = null;
            ˏ();
        }
        this.ˏ = null;
    }
}
